export default{
	getNeteaseCloudMusicUrl(){
		try {
			const value = uni.getStorageSync('NeteaseCloudMusicApi')
			if (value && value !== '') {
				return value
			}else{
				uni.showToast({
					title: "请先配置API",
					duration: 2000,
					icon:"error"
				})
			}
		} catch (e) {
			uni.showToast({
				title: "请先配置API",
				duration: 2000,
				icon:"error"
			})
		}
	},
	async findMusic(that,name){
		var url = that.NeteaseCloudMusicTool.getNeteaseCloudMusicUrl()
		if(!url || url === ''){
			return
		}
		url = url + "/search";
		console.log(url)
		const res = await uni.request({
		    url: url,
			method:'GET',
		    data: {
		        "limit": "20",
				"keywords": name,
				"type": "1",
		    }
		})
		console.log(res.data)
		return res.data
	},
	async findMusicUrl(that,id){
		var url = that.NeteaseCloudMusicTool.getNeteaseCloudMusicUrl()
		if(!url || url === ''){
			return
		}
		url = url + "/song/url";
		console.log(url)
		const res = await uni.request({
		    url: url,
			method:'GET',
		    data: {
		        "id": id
		    }
		})
		console.log(res.data)
		return res.data
	},
	async findMusicList(that,name){
		var url = that.NeteaseCloudMusicTool.getNeteaseCloudMusicUrl()
		if(!url || url === ''){
			return
		}
		url = url + "/search";
		console.log(url)
		const res = await uni.request({
		    url: url,
			method:'GET',
		    data: {
		        "limit": "50",
				"keywords": name,
				"type": "1000",
		    }
		})
		console.log(res.data)
		return res.data
	},
	async findMusicListMsg(that,id){
		var url = that.NeteaseCloudMusicTool.getNeteaseCloudMusicUrl()
		if(!url || url === ''){
			return
		}
		url = url + "/playlist/track/all";
		console.log(url)
		const res = await uni.request({
		    url: url,
			method:'GET',
		    data: {
		        "limit": "0",
				"id": id,
		    }
		})
		console.log(res.data)
		return res.data
	}
}